package com.lilong.jwt.common.util;

import com.lilong.jwt.common.exception.ExceptionEnum;
import com.lilong.jwt.common.exception.HydrauException;
import org.springframework.util.ObjectUtils;

public class ResultUtil {

    public static ResultBean SUCCESS(Object object) {
        ResultBean result = new ResultBean();
        result.setCode(ExceptionEnum.SUCCESS.getCode());
        result.setMessage(ExceptionEnum.SUCCESS.getMsg());
        result.setData(object);
        return result;
    }

    public static ResultBean ERROR(Integer code, String msg) {
        ResultBean result = new ResultBean();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

    public static ResultBean ERROR(HydrauException e) {
        ResultBean result = new ResultBean();
        result.setCode(e.getCode());
        result.setMessage(e.getMessage());
        if (!ObjectUtils.isEmpty(e.getDetail())) {
            result.setData(e.getDetail());
        }
        return result;
    }
}
